|
|
Hi!
I am a newbie to Javascript and am having a few difficulties!
I am trying to run 2 seperate Javascript functions ("hidden" and "verify") from 1 submit button. Both of these functions have worked successfully when run seperately from the submit button - any ideas how I combine the code.....
Code is:
1) This pulls data from a text box in an iframe and puts it into a hidden text box in my main page form.
<script>
function hidden(){
window.document.forms["second"].elements["hiddenmodel"].value = window.frames["pic"].document.forms["frmModel"].elements["model"].value;
}
</script>
2) This runs the hidden function (above) when submit button pressed.
<form method="get" action="asp_add.asp" name="second" onsubmit="hidden()">
3) This validates that data has been input in mandatory fields.
<script language="JavaScript">
function verify(form) {
var errors = "";
var msg = "Your details were not submitted because of the following error(s).\n\n";
if (form.make.value == "" || form.model.value == "") {
errors += " - you must enter selection criteria to proceed." +"\n\n" }
if (errors != "")
{
alert(msg + errors + "Thank you.")
return false
}
else
{
second.action ="asp_add.asp"
return true
}
}
</script>
4) This runs the verify function (above) when the submit button is pressed.
<form method="get" name="second" onsubmit="
this.make.optional = true;
this.model.optional = true;
return verify(this);">
Many thanks in advance for any help...
Cathy
|
|
|
|
Hi Cathy
Not entirely sure I understand what you're after, but can't you simply create a third function, and then onsubmit of the form call both the other functions from there?
as in
function formsubmit(form)
{
hidden()
verify(form)
}
<form method="get" name="second" onsubmit="
this.make.optional = true;
this.model.optional = true;
return formsubmit(this);">
<Added>
sorry the formsubmit function should probably be
function formsubmit(form)
{
hidden()
return verify(form)
}
|
|
|
|
Hi Jeff - Many thanks for your quick response.
I have amended the onsubmit to run a new function that calls my hidden and verify functions, as you suggested, but it doesn't work.
The verify function doesn't pick up empty mandatory fields and the hidden function doesn't copy a value into a hidden field, which should be sent in the URL to page asp_add.asp. When submit is pressed, the current page (upd_search.asp) is refreshed and passed some empty querystring parameters.
Both the verify function and the hidden function are tried and tested running seperately from the submit button.
The hidden function has always been coded in <script> tags within the <head>. The verify function within <script language="JavaScript"> tags within the body. Does this make any difference? Which tags should my new formsubmit function be within?
Any help much appreciated, as my PC is heading towards the open window as we speak! ;-)
Cathy
|
|
|
|
|
|
|
|