...

View Full Version : how to enable dynamic form fields if JS turned off.



jasonpc1
07-04-2011, 12:26 AM
I have a form that only shows the submit (update) buttons if the value select field beside it is changed. But what is someone has JS disabled, how can I enable them?



<select title="3553" name="3553" onchange="JavaScript:document.cart.add3553.disabled=false;">

sunfighter
07-04-2011, 05:34 AM
You can not enable a users javascript. You have to ask them to do it.

You can put up a message that js is needed to use your site or
On the page that needs js make an alert that asks them to turn js on and do a onload that will remove it if they do have it on.

Those are the methods i use. Any other ideas?

jasonpc1
07-04-2011, 07:33 AM
Having re-read me own post, I realised I was asking the question the wrong way around.

What I should be asking is how do I set only the 'update' submit buttons, only the buttons within a certain form called 'cart', to 'disabled'

My page can have two forms and on certain pages up to three forms, each form of course has a different name. So I do not want to disable every submit button on the page, only those within the form called 'cart'

Philip M
07-04-2011, 07:38 AM
If Javascript is not enabled in the user's browser, then you cannot use Javascript to disable or enable some or all submit buttons. You need to advise your users that they must have Javascript enabled to use the site.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

jasonpc1
07-04-2011, 08:10 AM
ok what i was after is to allow all buttons to be enabled and only if they have JS enabled woyuld I be able to disable them to prevent the buttons being clicked for the hell of it when nothing was changed on the page.

I have been rooting around again and got this code before which changed all the input fields to autocomplete off, but when I change the code to check for submit buttons it fails.

here is what I have...
the if statement fails with...

Error: theTags[i].name is undefined



function disableUpdateSubmit() {
var theTags = document.getElementsByTagName('*');
for(i=0;i < theTags.length;i++) {
if(theTags[i].name.substring(0, 2) = 'add') {
theTags[i].disabled=true;
}
}
}

devnull69
07-04-2011, 08:16 AM
I assume not all of your tags on the page have a name attribute? So you can not extract a substring from it ... that's what the error is about


function disableUpdateSubmit() {
var theTags = document.getElementsByTagName('*');
for(i=0;i < theTags.length;i++) {
if(theTags[i].name) {
if(theTags[i].name.substring(0, 2) = 'add') {
theTags[i].disabled=true;
}
}
}
}

jasonpc1
07-04-2011, 08:24 AM
oh I see, I now have this errror showing..

Error: invalid assignment left-hand side

on this line


if(theTags[i].name.substring(0, 2) = 'add') {

jasonpc1
07-04-2011, 08:29 AM
the submit buttons that i wish to disable all start with

'add'

i.e.

add124
add7647
add24565
add2
add6337

devnull69
07-04-2011, 08:39 AM
Sorry, my bad

I oversaw the second more obvious mistake. The compare operator is == and not =


function disableUpdateSubmit() {
var theTags = document.getElementsByTagName('*');
for(i=0;i < theTags.length;i++) {
if(theTags[i].name) {
if(theTags[i].name.substring(0, 2) == 'add') {
theTags[i].disabled=true;
}
}
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum