/    Sign up×
Community /Pin to ProfileBookmark

Please help! Function problem with IE

I’ve been struggling to figure this out on my own for hours. I hope someone here can assist me with this problem. I am using a javascript function to pass variables to fields within a form and then to submit that form. Of course, it works fine in Firefox, but the values don’t seem to post to the other script in IE. Can anyone tell me if there is an obvious reason why this isn’t working with IE?

[B]I have a JS function as follows:[/B]
function dosubmit (action, roomid, floorid, complexid)
{
field = document.getElementById(‘action’);

if(action == 1){
field.value = ‘cancel’;
}else{
field.value = ‘select’;
}

field = document.getElementById(‘roomid’);
field.value = roomid;

field = document.getElementById(‘floor’);
field.value = floorid;

field = document.getElementById(‘complex’);
field.value = complexid;

form = document.getElementById(‘mainform’);
form.submit();

}

[B]That much is pretty straight forward, I hope. Here is the stuff in the body:[/B]
<form action=”../select_room.php” id=”mainform” method=”post”>

<?php
echo “<input name=’go’ type=’button’ onClick=’dosubmit($action, $roomid, $floorid, $complexid);’ value=’reserve’>”;
?>

<input name=”complex” id=”complex” type=”hidden” value=”” />
<input name=”floor” id=”floor” type=”hidden” value=”” />

<input name=”action” id=”action”type=”hidden” value=”” />
<input name=”roomid” id=”roomid” type=”hidden” value=”” />

</form>

THanks!!

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@sturz001Dec 28.2007 — It could be something to do with the id atrtribute. This would be the way i would do it, but i myself hava had troubles with calling forms by their id's. My sugestion would be to try a call by name.

Please return the favour and help me Here
Copy linkTweet thisAlerts:
@toicontienDec 28.2007 — The name attribute has been deprecated on almost all HTML elements, save for form fields. Always use Ids on the FORM tag, so that is correct. What I think sturz001 is hinting at is a funny behavior with Internet Explorer having to do with document.getElementById, name and Id attributes.

The document.getElementById function will return any element whose Id OR name matches the string given to the function. This happens in Internet Explorer and is a bug or bad implementation of the document.getElementById function. As a general rule, never give any two HTML tags the same name as an Id elsewhere in the HTML document. Do you have an HTML tag whose name attribute is "action" and then another HTML tag whose Id attribute is "action"? That could be the cause of your problem.

I see you have a button named "action" whose Id is also "action". I don't think this would trip Internet Explorer up, but it might. I would suggest prepending the Ids of the form fields with "field_" to ensure your Ids won't clash with your names in Internet Explorer.
Copy linkTweet thisAlerts:
@toicontienDec 28.2007 — Are you getting a JavaScript error in Internet Explorer too? Please post that if you can find it. You'll see a yellow triangle icon with an exclamation point towards the lower left of the Internet Explorer window. Double click that to see the JavaScript errors on the page. Sometimes you'll have more than one and you'll need to click the "Previous" button to see all the errors.
Copy linkTweet thisAlerts:
@sedge9authorDec 29.2007 — Thank you both for your response!

toicontien -

I only have one input field with the id of "action." I'm taking your suggestion of prepending "field_" to all of my id fields.

My event handlers are located inside of a php function. Is there any known issues with this & IE?

Anyway, I'll be back on the case Monday when I'll post the specific error, and probably agonize on about it still not working in IE :]

Thanks for the helpful advice!
Copy linkTweet thisAlerts:
@sedge9authorJan 10.2008 — In case anyone was following this...I included the helpful advice of the other posts in this thread which amounted to better coding practices but didn't fix my problem.

I had a php function call roomurl with an event handler inside. So we'll say it looked kind of like thisL

<script>see the doSubmit function I posted earlier</script>

function phpfunction($var1, $var2, $var3, $var4){

echo "<input name='reserve' id='reserve' class='rr_btn' type='button' onClick='dosubmit($var1, $var2, $var4, $var4);' value='reserve'>";

}

In the body I had:

<body>

<form action="" method="post" id="mainform" target="_self">

<div><?php phpfunction('a', 'b', 'c', 'd') ?></div>

<input name="floor" id="field_floor" type="hidden" value="">


<input name="action" id="field_action"type="hidden" value="">

<input name="roomtype" id="field_roomtype" type="hidden" value="">

<input name="roomid" id="field_roomid" type="hidden" value=''>


</form>

</body>

The above wouldn't work in IE. Then finally I decided to try moving the hidden fields to the top of the form rather then keeping them at the bottom. So now the body looks like:

<form action="" method="post" id="mainform" target="_self">

<input name="floor" id="field_floor" type="hidden" value="">


<input name="action" id="field_action"type="hidden" value="">

<input name="roomtype" id="field_roomtype" type="hidden" value="">

<input name="roomid" id="field_roomid" type="hidden" value=''>

<div><?php phpfunction('a', 'b', 'c', 'd') ?></div>

</form>

</body>

Now it works...sigh..
×

Success!

Help @sedge9 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.22,
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,
)...