Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

JavaScript: form photo preview

max_file_size

  • Please log in to reply
4 replies to this topic

#1 usmanzm

usmanzm

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 22 August 2008 - 04:04 AM


<html>
<head>
<title>PHP dan JavaScript</title>
<SCRIPT language=javascript>
// Untuk Menampilkan/Preview Gambar
function preview(){
var nama=document.forms[0].FileGambar.value;
document.gambar.src=nama;
}
</SCRIPT>
</head>
<body >
<form action="" method="post" enctype='multipart/form-data' name="form1" target="_self">
<input type='hidden' name='max_file_size' value='1000000'>
Pilih Gambar :<br>
<input name="FileGambar" type="file" size="40" maxlength="100" onChange="preview()" onKeyUp="preview()" ><br>
<input name="Submit" type="submit" value="Simpan"><br><br>
<img src="" name="gambar" width="114" height="144">
</form>
</body>
</html>

Edited by Jordan, 01 October 2008 - 07:03 AM.
added php tags

  • 0

#2 Brandon W

Brandon W

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2092 posts
  • Location:Ipswich, Australia
  • Programming Language:C, Java
  • Learning:Java, C++, JavaScript

Posted 01 October 2008 - 05:23 AM

Just a tip mate. It makes it more neater and more understandable if you indent your code and also using PHP tags or CODE tags might help for others to view your code.

I also don't see any PHP in that script?
  • 0

#3 morefood2001

morefood2001

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1011 posts

Posted 01 October 2008 - 06:28 AM

First, Please use Code Tags. Second, That is not PHP, thats HTML with some JavaScript. Third, Indentation of code really helps :)

Thanks :)
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#4 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 01 October 2008 - 07:09 AM

I've added tags. Please use [noparse]

or or

or

(xx being the language you are posting code in)[/noparse] when posting code. There is no PHP in this code either and an explanation of the code would also be nice. I'll add on here for future readers:

The code above is a image uploading form using HTML and JavaScript. As the user changes or releases a key (onChange(), onKeyUp()) in the image file path box the JavaScript will "preview" the selected image in the gambar image. The code looks faulty in that an invalid path could be entered (such as every time you press a key if manually entering a path) and there is no error checking. Otherwise, a good idea.
  • 0

#5 Xav

Xav

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 8356 posts

Posted 05 October 2008 - 11:23 AM

Shouldn't they be HTML tags here, not PHP tags? There's not a trace of PHP in the entire code listing.
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?





Also tagged with one or more of these keywords: max_file_size

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download