Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript] Problem z modyfikacją href w znaczniku <a ..., getElementById, Uncaught TypeError: Cannot read property 'href'
bonio89
post
Post #1





Grupa: Zarejestrowani
Postów: 29
Pomógł: 0
Dołączył: 30.09.2009

Ostrzeżenie: (0%)
-----


Witam,
Mam skrypt do dopisywania parametru do hiperłącza. Problem w tym gdy podaje zmienna na wejściu i niby jest poprawna to wywala błąd: Uncaught TypeError: Cannot read property 'href' of null.

  1. <!doctype html>
  2. function modUrl(mid, idUrl){
  3. var tmp=document.getElementById(idUrl).href;
  4. tmp=tmp+'&mid='+mid;
  5. //alert (tmp);
  6. document.getElementById(idUrl).href=tmp;
  7.  
  8. }
  9. <meta charset="utf-8">
  10. <title>Dokument bez tytułu</title>
  11. </head>
  12.  
  13. <select name="todo">
  14. <script>modUrl("123", "urlS_1");</script>
  15. <option value="123" onClick="modUrl('123', 'urlS_1')">123</option>
  16. <option value="321" onClick="modUrl('321', 'urlS_1')">321</option>
  17. </select>
  18. <a id="urlS_1" href="index.php?page=test&action=sell&which=2">sprzedaj</a>
  19. </body>
  20. </html>


Ten post edytował bonio89 28.04.2015, 11:02:01
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 18.09.2025 - 13:01