Jump to content

[Resolvido] Problema esquezito


Gooden

Recommended Posts

Bom tou a tentar fazer um codigo k ao clicar no butao ele vai para uma pagina

<html>
<head>
<SCRIPT LANGUAGE="javascript">
function OnChange(dropdown)
{
   var baseURL =dropdown;
   top.location.href = baseURL;
   }
</SCRIPT>
</head>
<body>
<select name='select9'>
<option></option>
<option value="9">aa€</option>
<option value="10">aaa €</option>
<option value="11">aaaa €</option>
<option value="12">aaaaa €</option>
<option value="141">aaaaaa €</option>
</select>
<input type="submit" value="Comprar" NAME="btn9" onClick="OnChange(select9.value)" style="background-color:#EFA915;">
</body>
</html>

codigo n sei porque n funciona

o esquizito e quando uso onchange na select box ele funfa LOOL?

Link to comment
Share on other sites

Porque tens de indicar a referencia completa para o objecto. no submit, passa à tua função isto:

document.getElementsByName("select9")[0].value

ou seja, fica OnChange(document.getElementsByName("select9")[0].value)

a função getElementsByName retorna um array dos elementos com esse nome, como só há um, assuma a primeria posição, daí o [ 0 ]. Podes ver mais sobre o getElementsByName no site da w3schools.

Nick antigo: softclean | Tens um projeto? | Wiki P@P

Ajuda a comunidade! Se encontrares algo de errado, usa a opção "Denunciar" por baixo de cada post.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.