[Résolu] utilisation de onclick et location.href

utilisation de onclick et location.href [Résolu] - HTML/CSS - Programmation

Marsh Posté le 30-06-2010 à 09:25:06    

Bonjour,
 
J'ai un champ formulaire qui définit un nom d'utilisateur.
 
Une fois ce champ complété, je voudrais que lorsque l'utilisateur clique sur une image, il soit dirigé vers une url dont le chemin intégre son nom d'utilisateur.
 
Exemple : si je saisis toto, l'url va être http://hote/toto/index.php
 
J'ai commencé à coder ces quelques lignes mais je ne parviens pas à "parser" le contenu du champ et à insérer (question de syntaxe) correctement la variable sous location.href.
 

Code :
  1. <td align="left" style="width: 171px; vertical-align: middle;">
  2. <input type="text" style="width: 145px;" id="user" name="user">
  3. <img align="top" width="7px" height="7px" src="./images/star.png">
  4. </td>
  5. ...
  6. <input type="image" style="border-width: 0px;" onclick="location.href='http://hote/toto/index.php';" alt="Redirection" src="./images/demo.png" id="test" name="test">


 
Merci pour votre entraide.


Message édité par sneakz le 05-07-2010 à 10:30:14
Reply

Marsh Posté le 30-06-2010 à 09:25:06   

Reply

Marsh Posté le 01-07-2010 à 13:52:59    

salut,
 
tu dois pouvoir le faire avec

Code :
  1. <td align="left" style="width: 171px; vertical-align: middle;">
  2. <input type="text" style="width: 145px;" id="user" name="user">
  3. <img align="top" width="7px" height="7px" src="./images/star.png">
  4. </td>
  5. ...
  6. <input type="image" style="border-width: 0px;" onclick="location.href='http://hote/' + document.getElementById('user').value + '/index.php';" alt="Redirection" src="./images/demo.png" id="test" name="test">


 
Luc

Reply

Marsh Posté le 01-07-2010 à 17:11:55    

[:pingouino]

 

Il y a une raison pour ne pas faire ça proprement avec un paramètre normal, un formulaire en GET et une redirection vers la bonne URL en 301?

Spoiler :

et le markup me semble totozifiant...


Message édité par masklinn le 01-07-2010 à 17:13:50

---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 05-07-2010 à 10:10:49    

Merci pataluc, j'ai utilisé ' + encodeURIComponent(document.getElementById('user').value) + '

Reply

Marsh Posté le 05-07-2010 à 10:26:39    

J'peux avoir une réponse à ma question?


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 05-07-2010 à 10:29:51    

C'est fait proprement, seule la méthode change ... c'est un choix personnel. Le tout étant intégré dans une iframe.

Reply

Marsh Posté le 05-07-2010 à 10:44:03    

sneakz a écrit :

C'est fait proprement


Non [:pingouino]


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed