Jump to content

JavaScript: form photo preview

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
usmanzm

usmanzm

    Newbie

  • Members
  • Pip
  • 5 posts
<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


#2
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
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?

#3
morefood2001

morefood2001

    Speaks fluent binary

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

Thanks :)

#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I've added tags. Please use [noparse]
 or 
 or 
 or [highlight="xx"][/highlight] (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.

#5
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Shouldn't they be HTML tags here, not PHP tags? There's not a trace of PHP in the entire code listing.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums