/    Sign up×
Community /Pin to ProfileBookmark

Hiding Form Fields

I can’t believe I am having such a hard time with this and a hard time finding some guidance.

I have an order form that lists available products; where users enter a quantity value in a text box next to the items they want to order. The form action is POST and the form values are passed to a confirmation page with session variables. Everything works well to this point but I don’t know how to display only the ordered items on the confirmation page.

All of the default values are set to 0 so I thought perhaps I could use a simple Javascript function to hide the fields that contain a value = 0 such as:

[CODE]
function confirm(){
var a = eval(document.myform.myfield.value);
var b = ….. and so on….

if (a==0 || a == ” “){
//some code to hide the field
}
}

[/CODE]

I have tried everything that I can think using internet research but to no avail. I’m not hoked on Javascript. If there is another easy way to display only the fields that have a value, please advise.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@NitecruzexJun 27.2011 — i really didnt get your question ? but heres something you can try...if the value is 0 get that element id and set its display property to none.
[CODE]document.getElementById("id").style.display="none";[/CODE]

OR?

you can set the element type to hidden ( if its a text box for example)

[CODE]document.getElementById("id").type="hidden";[/CODE]

Paste your code here and it will be much easier to figure out the problem.
Copy linkTweet thisAlerts:
@nosillakauthorJun 28.2011 — This seems like it should be an easy thing but I cannot get anything to work however I will try to clarify my question.

I have an order form with several input fields such as:
[code=html]<input name="KSQTY" type="text" id="KSQTY2" value=" 0" size="2" style="text-align:center">[/code]
The name of the field represents the product identification and the input is the quantity ordered. All fields have a default value of 0. When the customer clicks the submit button, the form data is passed to a confirmation page via session variables. The confirmation page is where the customer can view and print a copy of their order before actually submitting it. Currently the page displays all products and I would like it to display only the items that have a value greater than 0. The code (in part) that I have this far is as follows:
[code=html]<body onLoad="getOrder()">[/code]
[CODE]function getOrder(){
var a = eval(document.confirm.WQTY.value);
var b = eval(document.confirm.OQTY.value);
var c = eval(document.confirm.VQTY.value);
var d = eval(document.confirm.WWB.value);
var e = eval(document.confirm.OWB.value);
var f = eval(document.confirm.VWB.value);
var g = eval(document.confirm.KSQTY.value);
var h = eval(document.confirm.POSTQty.value);
var i = eval(document.confirm.WWC.value);
var j = eval(document.confirm.SUBSC.value);
var k = eval(document.confirm.BUN.value);

if (a==0 || a==""){
document.getElementById("WQTY").type="hidden";

}


}

</script>[/CODE]

Seems simple right? But it doesn't work. The field is still displayed with it's 0 value. ?
Copy linkTweet thisAlerts:
@nosillakauthorJun 28.2011 — DOH! I figured it out. Stupid me :mad:

my variables should have bee set as:
[CODE]var a = document.getElementById('WQTY').value;[/CODE]

Once I changed all the variables, everything worked fine.

Thanks for your help.
Copy linkTweet thisAlerts:
@NitecruzexJun 28.2011 — No problem mate ?
×

Success!

Help @nosillak 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...