/    Sign up×
Community /Pin to ProfileBookmark

get form field value (FireFox)

hey
How can I get form text field value so that it wold work in firefox?
I have this:

[code=php]
document.myForm.fieldname.value
[/code]

works fine in IE but firefox says that document.myForm has no value ?

I hate firefox, it never likes my scripts ?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@cgishackAug 21.2008 — does your [B]form [/B]have a name equal to 'myForm' and textbox name = fieldname?

Sometimes IE will get the ID if there is no name.

if you gave the textbox an ID you get the value also by:
<i>
</i>document.getElementById('fieldname').value


If you post your HTML it might be easy to give the correct answer.

Drew
Copy linkTweet thisAlerts:
@alexusauthorAug 22.2008 — get element by id givese me the same error stating that element (coresponding to the text fied) has no propertis ?

below is the full script that I need to make fully Mozilla compatibe. (it does work under IE)
[code=php]
/AJAX
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
alert("firefox detected");
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
//alert("Microsoft V2");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser does not support XML protocol, please check your settings");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
//document.myForm.time.value = ajaxRequest.responseText;
alert(ajaxRequest.responseText);
//Below lets process the request from server and output proper information to the users
myArray=ajaxRequest.responseText.split("^");
alert(myArray[0]);

//lets find out what icon should we show
/*if(myArray[0] == "stop"){
window.s_icon.innerHTML="<img border='0' src='images/stop_ico.gif' width='60' height='58'>";
}else if (myArray[0] == "warning"){
window.s_icon.innerHTML="<img border='0' src='images/warn_ico.gif' width='60' height='58'>";
}else if (myArray[0] == "info"){
window.s_icon.innerHTML="<img border='0' src='images/info_ico.gif' width='60' height='58'>";
}
*/

//Show the custom text
//window.m_text.innerHTML = myArray[1];
document.getElementById(m_text).innerHTML = myArray[1];

//Check if we shoud disable user account
if (myArray[2] == "disable"){
//window.myForm.auth_pass.style.backgroundColor="Red";
//window.myForm.accept.style.display ="none";
//alert("DISABLE");

//Maybe we just hide the input form on disable
window.input_unit.style.display="none";

}


if(myArray[0] != ""){
//if we got the icon lets show message window
//window.test2.style.display="block";
document.getElementById(test2).style.display="block";
}else{
document.getElementById(test2).style.display="none";
}

}
}

//build request string with username
//myRequest = "message.php?username=" + document.myForm.auth_user.value + "&site=" + mySite;
myRequest = "message.php?username=" + document.getElementById(auth_user).value + "&site=" + mySite;
//alert("Username: "+ myRequest);
ajaxRequest.open("GET", myRequest, true);
ajaxRequest.send(null);
try{
//alert(ajaxRequest.status);
ajaxRequest.status;
}catch (e){
//ok the status returns nothing or gives an error so we would assume that connection error detected
//alert("I did not get the status request confirmed");
//window.m_text.innerHTML="<b>WARNING</b><br>This is automated watchdog notification system. ";
//window.s_icon.innerHTML="<img border='0' src='images/net_ico.gif' width='60' height='58'>";
//now lets show the window to the user
//window.test2.style.display="block";
}
}

[/code]
Copy linkTweet thisAlerts:
@cgishackAug 22.2008 — is auth_user the ID ?

if so, place ' ' around it.

document.getElementById('auth_user').value
Copy linkTweet thisAlerts:
@alexusauthorAug 22.2008 — yay it worked =)

damn why wouldnt Firefox debuger wouldnt just tell me that ? I spent last 3 hours trying to get it working

Thanks... let me now go and clean up the script ?
×

Success!

Help @alexus 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.24,
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,
)...