-
Jul 11th, 2013, 07:05 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Javasript Syntex Error
I am not sure why keep getting syntax error on the high lighted line of code. pls help "code hint may not work until you fix error"
Code:
<sript>
window.onload = function() {
document.getElementById('checkstatus_0').onchange = disablefield;document.getElementById('checkstatus_1').onchange = disablefield;
}
-
Jul 11th, 2013, 08:44 AM
#2
-
Jul 12th, 2013, 02:54 AM
#3
Thread Starter
Addicted Member
Re: Javascript Syntex Error
I am sorry for the omission
Code:
script
window.onload = function() {
document.getElementById('phone_no').onchange = disablefield;
document.getElementById('phone_yes').onchange = disablefield;
}
function disablefield()
{
if ( document.getElementById('phone_no').checked == true ){
document.getElementById('PhoneNumber').value = '';
document.getElementById('PhoneNumber').disabled = true}
else if (document.getElementById('phone_yes').checked == true ){
document.getElementById('PhoneNumber').disabled = false;}
}
</script>
-
Jul 12th, 2013, 03:10 AM
#4
Re: Javascript Syntex Error
Hi there alobi
do the "phone_no" and "phone_yes" refer to <input type="checkbox"> elements?
~ the original bald headed old fart ~
-
Jul 12th, 2013, 05:44 AM
#5
Thread Starter
Addicted Member
Re: Javasript Syntex Error
Good, Morning,
I may have posted an old code, please forgive me. I am sorry, here is the corrected code and I am still having the same issue. Also
I notice another problem. The code is not doing what I expected and I do not think it is related to the syntax error.
I want to be able to disable the phone number textbox when the lastname option button is clicked, and disable the lastname textbox when the option button for phone number is clicked. The aim is to make sure that users do not enter information in both textboxes at the same time.
Thank you for your time
HTML Code:
<html>
<head>
<title>Disable</title>
<script>
window.onload = function() {
document.getElementById('phone').onchange = disablefield;
document.getElementById('name').onchange = disablefield;
document.getElementById('LastName').disabled = false;
document.getElementById('PhoneNumber').disabled = false;
document.getElementById('name').checked = false;
document.getElementById('phone').checked = false;
}
function disablefield()
{
if ( document.getElementById('name').checked == true ){
document.getElementById('PhoneNumber').value = '';
document.getElementById('PhoneNumber').disabled = true;
document.getElementById('LastName').disabled = false;}
else if (document.getElementById('phone').checked == true ){
document.getElementById('LastName').value = '';
document.getElementById('LastName').disabled = true;
document.getElementById('PhoneNumber').disabled = false;}
}
</script>
</head>
<body>
<form action="#" method="get" name="admin">
Phone: <input type="radio" name="idmethod" value="phone" id="phone"/>
<input name="PhoneNumber" type="tel" id="PhoneNumber" size="25" />
<br/><br/>
Name:<input type="radio" name="idmethod" value="name" id="name"/>
<input name="LastName" type="text" id="LastName" size="25" />
</form>
</body>
</html>
-
Jul 12th, 2013, 06:02 AM
#6
-
Jul 12th, 2013, 07:51 AM
#7
Re: Javasript Syntex Error
The code is not doing what I expected and I do not think it is related to the syntax error.
It most certainly is related... it's not doing what you expect because the script is "broken" and so it can't run....
however... it seems to almost work jsut fine for me... I don't get any syntax errors... and when I click one option button the other text box clears out... tried it in IE, and Firefox...
I did notice a little bit of odd behaviour in IE though, after clicking the option button, it wouldn't clear out the old value until I clicked into the new textbox or somewhere else... so I question the OnChange event... if maybe there's a better event that should be handled.
-tg
-
Jul 12th, 2013, 08:42 AM
#8
Thread Starter
Addicted Member
Re: Javasript Syntex Error
I created a new page, copied and pasted the same code on the page, it works fine. Thanks
-
Jul 19th, 2013, 05:02 AM
#9
Registered User
Re: [RESOLVED] Javasript Syntex Error
yeah you be type <script> not like <sript>.this is wrong one.and i agreed with coothead.this is one example for you used to display the current date.
<script>
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|