Window.location.href cuts off parameter

Discussion in 'JavaScript' started by fex, Apr 19, 2009.

  1. #1
    Hello,

    I've got a news and guestbook system created on my website working with use of a database. The id (in my database table) is being used to remove a post.

    A jscript does the following:
    function confirmRemove(var_id){
    	if(confirm('Wilt u deze post echt verwijderen?')){
    		window.location.href = 'index.php?page=gastenboek&do=remove&id=' + var_id + '#anc';
    	}
    }
    Code (markup):
    When I hover over a link directed to this function the var_id is correct (let's say the id is 090414144354). But when I click the link the var_id is missing the leading zero (so the id becomes 90414144354). This causes my file not to be deleted of course cause it is not found.
     
    fex, Apr 19, 2009 IP
  2. joep1978

    joep1978 Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The problem looks like Javascript is treating the parameter like an integer, not a string. Integers don't have leading zeros.

    I don't know how you're calling the function but confirmRemove(090414144354); would cause this problem - you'd need to do confirmRemove('090414144354');
     
    joep1978, Apr 19, 2009 IP
  3. fex

    fex Peon

    Messages:
    89
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You're totally right, guess I was looking too hard.

    Thx ;)
     
    fex, Apr 19, 2009 IP