Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Javascript called from within an HTML form question (https://www.warriorforum.com/programming/1216052-javascript-called-within-html-form-question.html)

Alex Cohen 6th September 2016 04:37 PM

Javascript called from within an HTML form question
 
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

robomedia 7th September 2016 03:20 AM

Re: Javascript called from within an HTML form question
 
Try closing the script tag <script type="text/javascript">

robomedia 7th September 2016 03:21 AM

Re: Javascript called from within an HTML form question
 
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;" />

element121 8th September 2016 04:52 AM

Re: Javascript called from within an HTML form question
 
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;">

Badaudio 30th September 2016 05:40 AM

Re: Javascript called from within an HTML form question
 
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


All times are GMT -6. The time now is 07:13 PM.