/    Sign up×
Community /Pin to ProfileBookmark

setting button properties in onClick function and then submit()

I’m trying to set the properties of a submit button in the onClick function I specify in the button tag descriptor, but none of the assignments are “working”, and the call to
document.form1.submit();

Seems to have no effect. The form submits whether I comment out the document.form1.submit(); call or not.

And the assignment doesn’t work either.

The alert works and displays the value passed in correctly.

What I want to do is to have default button text, (set by the “value=buttonText” param) but have it overridden in the onClick function so it gets passed into the query string.

Here’s the button descriptor:
<body>
<form name=”form1″ >

<INPUT TYPE=”SUBMIT” NAME=portname VALUE=DefaultBtnTxt onClick=submitTest(“<c: out value=”${easport.name}”/>”) >

</form>
</body>

Here’s the onClick function
<script type =”text/javascript”>
function submitTest(port)
{
alert(“submit! port: ” + port );

document.form1.portname.value=port;
alert(“submit!” + document.form1. );
document.form1.submit();
}

</script>

This seems like it’s right is is pretty much straight out of an example I have to work with from abook. (Visual Javascript 2nd Edition)

Any help or pointers is appreciated.

Ed

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@toicontienMar 15.2007 — Like the anchor tag, you can return true or false to nullify a click on a button.
function submitTest(port)
{
alert("submit! port: " + port );

document.form1.portname.value=port;
alert("submit!" + document.form1. );
//document.form1.submit();
return true; // Causes the button click to go through, which submits the form.
}
Copy linkTweet thisAlerts:
@edderdauthorMar 15.2007 — It looks as though it's submitting ok, but this line is failing I think:

document.form1.portname.value = port;

<script type ="text/javascript">

function submitTest(port)

{

alert("submit! port: " + port + " port: ");

document.form1.portname.value = port;

alert("test");

document.form1.submit();

return true;

}

I never see the second alert("test") so the assignment must be failing...

Doesn't the

<form name="form1" > set the formname correctly?

Thanks,

Ed
Copy linkTweet thisAlerts:
@edderdauthorMar 15.2007 — Ok, Getting there, but now the value I assign to the value field never makes it to the query string.

I created a new button descriptor:

<BUTTON type="submit" name=portname value="SubmitButton" onClick=submitTest("<c:out value="${easport.name}"/>") >whatever</BUTTON>

I restructured the document and now I can get past the assignment and the submit() call, but it still appears that the assignment

document.form1.portname.value = port;

assigns the value but the button value never ends up in the query string.

<script type ="text/javascript" language="javascript">

function submitTest(port)

{

alert("submit! port: " + port + " port: ");

document.form1.portname.value = port;

document.form1.submit();

alert("test. Port: " + document.form1.portname.value );

return true;

}

</script>

The second alert displays the assigned value passed into the function, but

The querystring still contains the text "portname=SubmitButton" from the

<BUTTON type="submit" name=portname value="SubmitButton" onClick=submitTest("<c:out value="${easport.name}"/>") >whatever</BUTTON>

button descriptor.

?
×

Success!

Help @edderd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...