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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submit script not working in Safari

Status
Not open for further replies.

cfsponge

Programmer
Feb 22, 2006
44
US
I have a form being submitted by JS, but doesn't work in Safari (though no error is produced). Here is the code:

<script>
function goto() {
var f;
f = document.frm12;
f.sectionid.value = 29;
f.submit();
}
</script>

<form method='post' action=' name='frm12'>
<input type='hidden' name='sectionid' value='' />
Click <a href='javascript:goto()'>here</a> to view list of merchants with similar products.</form>
 
in addition to that, i'd make these changes:

Code:
<script type="text/javascript"><!--
function goto() {
    var f = document.forms['frm12'];
    f.elements['sectionid'].value = 29;
    f.submit();
}
//--></script>

Code:
<form method='post' action='[URL unfurl="true"]http://gotosite/'[/URL] name='frm12'>
    <input type='hidden' name='sectionid' value='' />
    Click <a href='#' onclick='goto(); return false;'>here</a> to view list of merchants with similar products.
</form>



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks to both of you for these recommendations.
 
<script type="text/javascript">
function goto() {
var f;
f = document.forms['frm12'];
f.elements['sectionid'].value = 29;
f.submit();
}
</script>

<form method='post' action=' name='frm12'>
<input type='hidden' name='sectionid' value='' />

Click <a href='javascript://' onClick='goto(); return false;'>here</a> to view list of merchants with similar products.
</form>
 
I just created a small test harness and then tested it in Safari:
Code:
<html>
<head><title>Safari Submit Test File</title>
<script type="text/javascript">
function sendit() {
	document.getElementById('myForm').submit();
}
</script>
</head>
<body>
<form action="" method="get" id="myForm">
	<input type="text" name="key" value="something"/>
</form>
<p>Click <a href="#" onclick="sendit(); return false;">here</a>!</p>
</body>
</html>
The code doesn't use method="post", but it works equally well if you change it to use post. If you are having a problem... it is not Safari at fault.

Post a link to your page and we can take a closer look.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Thanks for the workaround, BabyJeffy, but altering the code to accept GET for the variable isn't worth all the code changes that would have to take place right now. I will definitely keep this for future reference.

Here is the current page with the code. Using stylesheets for masking the submit button.

 
babyjeffy said:
The code doesn't use method="post", but it works equally well if you change it to use post...
All you would have to do is change it from using get to post... so... at most 7 keypresses [smile]

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Well, if it is only as a GET submission, then yes, it is resolved.
 
Actually, as I am rereading it, it does show that Safari does indeed submit, though their description uses the <em>.onsubmit</em> event, instead of <em>.submit</em>. I have to re-test this code to make sure.
 
No - quirksmode didn't lie - they say Safari does support it (there's a big green "yes" in the safari column for the submit event).

Maybe you were looking at the "select" event above it?

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan,

this is an ongoing post. i, at some point or another, thought this code was being called from the form's onsubmit event. the onsubmit event won't fire when a form is submitting via script.

this is where my confusion lay. thanks.



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
If the code submits when the method is get but not when it's post, I'd be surprised.

More likely is the poster's back-end is checking only a GET collection rather than a GET or POST collection for the submitted data.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Just to recap my first post:
The code doesn't use method="post", but it works equally well if you change it to use post...
And then my last post:
All you would have to do is change it from using get to post... so... at most 7 keypresses
I'm picking that you all missed it. There are NO problems using submit with safari regardless of the method you choose to use.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top