Closed Thread
Thread Tools Search this Thread
Unread 6th Sep 2016, 04:37 PM   #1
Alex the Copy Navigator
War Room Member
 
Alex Cohen's Avatar
 
Join Date: 2007
Location: York County, Pennsylvania
Posts: 2,692
Thanks: 428
Thanked 2,006 Times in 1,212 Posts
Default
Javascript called from within an HTML form question
Share on: 
fb share twitter share gplus share more share

Can you tell me why the value within this form input field does not clear when I click it?

Here's the code...

<head>
<script type="text/javascript"
function change()
{
document.getElementById("myField1").value="";
}
</script>
</head>

<input type="text" id="myField1" name="email" value="Enter Email" style="height:45px;width:463px;font-size:14pt;" onClick="javascript:change()" />

Thanks.

Alex
Alex Cohen is offline  
Unread 7th Sep 2016, 03:20 AM   #2
Active Warrior
 
Join Date: 2014
Posts: 84
Thanks: 5
Thanked 11 Times in 10 Posts
Default
Re: Javascript called from within an HTML form question
Share on: 
fb share twitter share gplus share more share

Try closing the script tag <script type="text/javascript">
robomedia is offline  
Unread 7th Sep 2016, 03:21 AM   #3
Active Warrior
 
Join Date: 2014
Posts: 84
Thanks: 5
Thanked 11 Times in 10 Posts
Default
Re: Javascript called from within an HTML form question
Share on: 
fb share twitter share gplus share more share

or even better try placeholder instead of value and drop that JS
<input type="text" id="myField1" name="email" placeholder="Enter Email" style="height:45px;width:463px;font-size:14pt;" />
robomedia is offline  
Unread 8th Sep 2016, 04:52 AM   #4
Active Warrior
 
Join Date: 2015
Location: Canada
Posts: 43
Thanks: 0
Thanked 7 Times in 7 Posts
Default
Re: Javascript called from within an HTML form question
Share on: 
fb share twitter share gplus share more share

Have a look at upgrading to HTML5 also, you can upgrade to use the email type and the required attribute:

<input type="email" required name="email" placeholder="Enter Email" style="height:45px;width:463px;font-size:14pt;">

element121 is offline  
Unread 30th Sep 2016, 05:40 AM   #5
Warrior Member
 
Badaudio's Avatar
 
Join Date: 2016
Location: United Kingdom
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: Javascript called from within an HTML form question
Share on: 
fb share twitter share gplus share more share

You must use the placeholder attribute for your form input elements. No need to have javascript there.

I would also recommend not using inline-css, to prevent clutter. Separate concerns by creating an external stylesheet and writing the following:

Code:
input {
    height: 45px;
    width: 463px;
    font-size: 14pt;
}
Then your input simply becomes:

Code:
<input type="text" id="myField1" name="email" placeholder="Enter Email">
Much cleaner

Badaudio is offline  
Closed Thread


Bookmarks

Tags
called, form, html, inside, javascript, question

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 03:37 AM.