Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,415
    Thanks
    269
    Thanked 32 Times in 31 Posts

    converting output into JQuery

    Here is the original code.

    Code:
    $return_html .= '<input type="hidden" id="index_page" value="' . parent::$index_value . '"/>';
    $return_html .= '<input type="hidden" id="script_name" value="' . $vars['SCRIPT_VALUE'] . '"/>';
    the problem is that this is in a file which processes all together and in doing so it outputs the input tags into the header which obviously they dont belong and it does not pass w3c.


    so im trying to convert them using JQuery so i can use the .insertAfter function. The name of the div after the header is loaded is called top_container so i wanted to load the inputs after top_container. I also tried wrapping this inside a

    Code:
    $(document).ready(function() {
    but that also did not work so i removed that..

    here is what i have so far that does not work..

    Code:
     $return_html .= '<script type="text/javascript">  
    $('<input type="text"  id="index_page" value="' . parent::$index_value . '"/>').insertAfter('.top_container');</script>';
    
    
     $return_html .= '<script type="text/javascript">  
    $('<input type="text"  id="script_name" value="' . $vars['SCRIPT_VALUE'] . '"/>').insertAfter('.top_container');<script>';
    im guessing there might be syntax issue because i get the ever popular white page lol..

    am i close

    thanks


    wonder if it might be better to just add a new empty div to the header and use .load to load those into that div.. mmmmm interesting


    i tried this too not working

    Code:
     $return_html .= '<script type="text/javascript">  
                            $("#affcoup_inputs").load("doinput.txt"); 
                            </script>';
    i did a txt file because that is what was in the example i found, it had html tags in a text file so i did it the same

    so inside that txt file are these

    Code:
    <input type="text"  id="index_page" value="' . parent::$index_value . '"/>
    <input type="text"  id="script_name" value="' . $vars['SCRIPT_VALUE'] . '"/>
    and then i have a div in the first part of the body like so


    <div id="affcoup_inputs"></div>


    but it does not get loaded with the inputs...
    Last edited by durangod; 07-15-2014 at 03:55 PM.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Let me guess: Normally you are using PHP?

    The concatenation operator is '+' rather than '.' in Javascript/jQuery. But it seems like you are mixing PHP with Javascript code, because there is no '::' operator in Javascript/jQuery, but there is a '$' method, which most certainly doesn't exist in PHP.

    Example:
    Code:
    $('<input type="text"  id="index_page" value="' . parent::$index_value . '"/>')
    Here you are building a PHP string (. concatenation and :: operator) but then the resulting '$' method would be Javascript. This cannot work.

    Normally, in PHP, you'd have to output Javascript/jQuery code using PHP echo or print or <?=

  • Users who have thanked devnull69 for this post:

    durangod (07-15-2014)

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,415
    Thanks
    269
    Thanked 32 Times in 31 Posts
    Let me guess: Normally you are using PHP?
    ahhhhh that made me laugh like heck, im that obvious huh lol.... nice one...

    oh now i understand much better, i need to switch modes, got it, thanks. I figured i could just go back to basic js and just put the inputs in a div where i want them in the header and then load the values by calling the function in the header from this file above with the values, and then loading the input values using document.getElementById that much i understood, i guess jQuery does make things easier from what i have read so far, so i might still stick with this at least to learn . Why they would put inputs in the header i will never know, all it does is track the page id and the script id is pretty constant, they could have put it anywhere in the body section and gotton the same results, lazy coding i guess. lol

    Thanks for the reply

  • #4
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,415
    Thanks
    269
    Thanked 32 Times in 31 Posts
    i guess jQuery is just not my friend lol ...

    but this saved my day sessionStorage.setItem what a GREAT function to have ..

    great read as well.. https://developer.mozilla.org/en-US/...PI/DOM/Storage

    job done... thanks mozilla for publishing that...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •