Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update form value on submit

Status
Not open for further replies.

macca2424

Programmer
Jul 23, 2007
21
GB
Hi i have a form below, i have some javascript to validate if the text box is empty.

what i need to do is

if the text box "qtext" is empty show alert

if the text box "qtext" is not empty and the value = 8 then update the value of the form element "answer" to "1"
then submit the form

else set the text box "qtext" to value of "0" and submit the form

**form**

<input type="text" name="qtext" />
<input id="qone" name="Answer" type="HIDDEN"/>
<input type="submit" value="Submit" onclick="return TextType();"


**current javascript**

function TextType()
{

if ((form1.qText.value.length < 1) || (form1.qText.value.length > 1))
{

mesg = "You have not answered the question!\n"
mesg = mesg + "Please select an image"
alert(mesg);

return (false);
}

return (true);
}
 
ok yes i understand that, the only issue is
onsubmit="return ValValue();"

will not work as i need to use the reponse write function.
<% Response.Write ValValue %>

but this causes a issue, so how can can i display the function from the database?
 
yes thats exactly what i tried to do in the first place but then anything below that code does not get diplayed on my page, but i thought that would work?
 
ok i have it working after lots of playing around.

now back to the orginal function below, which i have changed slightly by adding another form element and using that to compair the qtext value.

but it is not validating the form even if it qtext is empty?

Code:
function TextType() {
    var qText = document.forms['form1'].elements['qtext'].value;
	var Actual = document.forms['form1'].elements['ActualAnswer'].value;

    if (qText == '') {
        alert('You have not answered the question!\nPlease select an image');
        return (false);
    } else if (qText == Actual) {
        document.forms['form1'].elements['answer'].value = '1';
        return (true);
    } else {
        document.forms['form1'].elements['qtext'].value = '0';
        return (true);
    }
}
 
Put an alert at the top of the function to make sure it's being called. Or get a JS debugger (several good ones like Firebug are available for free for Firefox).

If you don't learn basic debugging techniques, and rely on others all the time, life as a web developer will be painful and not at all enjoyable.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
hi yes i already did add a alert and it shows the alert but does not validate the text box
 
ok thanks i have installed firebug where do i go to debug javascript?

also just wondering if you know why the button below would be subitting the form in firefox?

it works fine in IE

Code:
<button class="NavButtons" onClick="window.location='ModuleQuestions.asp?ques=<% Response.Write prevpag %>'">Previous Question</button>
 
ok debugged it i get this error

var qText = document.forms['form1'].element ['qtext'].value; has no properties

 
Then you either have no form named 'form1', multiple forms names 'form1', no element inside 'form1' with a name of 'qtext', or multiple elements inside 'form1' with names of 'qtext'.

Check your case - 'qtext' is NOT the same as 'qText'.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
ok thanks, got it working

just last thing i have 2 buttons inside my form

next and previous

next submits the form and previous goes back to the previuos page, this works fine in IE

in firefox the previuos button actually submits the form aswell when it should redirect to the previuos page

any ideas what i can do?

Code:
<button class="NavButtons" onClick="window.location='ModuleQuestions.asp?ques=<% Response.Write prevpag %>'">Previous Question
</button>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top