Jump to content

ajoo

Members
  • Content Count

    735
  • Joined

  • Last visited

Everything posted by ajoo

  1. Hi all ! This following code is supposed to pass an array from php to js:- $( document ).ready(function(){ alert('Yo'); var rs = <?php echo json_encode($rs);?>; alert(rs); }); instead javascript gives an error as Here's the simple php code as well: <?php $rs = [[1,2,3],[2,3,4],[3,4,5]]; // $rs = json_encode($rs); // This doesn't work either. ?> Please can someone point out the cause of error here. Thanks !
  2. ajoo

    pass a php array into js

    Thanks kicken ! for this alternate method. I do not fully understand it, but i'll look it up and if need be reopen this thread again. For the time being I have used the hidden field method suggested by Guru Barand ! Thanks loads !
  3. Hi all, This bit of code creates an array of input fields using php:- . . . $count = 10; echo "<tr>"; for($j=0; $j<$count; $j++) { echo "<td class=userinp> <input type='text' id='reply[]' value='' ></td>"; } echo "</tr>"; . . I wish to process the values entered in the input fields using JQuery. How can I fetch these user inputs into JQuery correctly ? My JQuery code is : $("#checkbutton").click(function(){ var test_arr = $("input#reply"); $.each(test_arr, function(i, item) { val = $(item).val(); alert(i+" : "+ val); }); }); which displays only the first value of the user input box. It is thus not fetching the array . Please point out the mistake or the correct method to achieve this. Thanks !
  4. Hi Guru Barand, For an HTML form that is not echoed out in php, the $value variable is checked that it exists, before it is echoed out. value="<?php if(isset($value)) echo html_escape($value);?>" How Is it possible to do the same here ? echo "<td> <input type='text' name='reply[]'class="ansbox" value='$value'></td>"; I have tried without success. Thanks.
  5. Hi, I have another but related question, so I will continue it here rather than in a new thread. I hope that is ok. SO if I modify my code as shown by Kicken like below:- <?php $count = 10; echo "<tr>"; for($j=0; $j<$count; $j++) { echo "<td> <input type='text' name='reply[]'class="ansbox" value=''></td>"; } echo "</tr>"; ?> and once the form has submitted the 10 post values, how can I print those back into their respective places using PHP not JS. I know it will have to echo them inside their value ' ' fields, having checked first if they have been set using isset( .. ), but I don't know the correct syntax to achieve that. Thanks all !
  6. Hi Kicken ! Thanks for the reply and for introducing me to the correct usage ! Even though I am getting the correct answer by using an array for both names and id's and then targeting the id to get the values of the array in JS, getting to know the correct form is so essential. Thanks loads for the correction !
  7. ok Guys, I got it ! While this var test_arr = $("input#reply"); works for dynamically created input boxes using JS, it does not work for boxes created using php. This works though test_arr = $("input[id='reply[]']"); I thought the first one looked more elegant ! Thanks !
  8. ajoo

    pass a php array into js

    Thank you Guru Barand ! While the above works fine when the js is enclosed in <script> tags and appended to the php file, it fails when the JS code is included as a separate js file. I guess the only way it works when the JS code is in its own file is as indicated by you, using a hidden field ! Thank you very much !
  9. Hi requinix, Thanks for that insight ! That's what I will do then. Thanks !
  10. Hi all ! I have created an array of input boxes and i wish to target each individually to check its contents after the user has input some values and pressed the click button. I have a fiddle at http://jsfiddle.net/crnsbz5a/13/ When the button is clicked, I want to compare the values of the input fields against the "a" array. If there is a mismatch I want to change the background color of the input box to a different color. I cannot figure out how to target the individual input box. Thanks all !
  11. Hi ! I am creating everything through javascript, since the number of fields are dynamic in the sense that they can change. I can need all the way from 10 to 20 fields and depending on that I would need to set them with different font and ( box ) size settings to have a proper page layout. Is it not a good idea to use JS to create the page ? What would you suggest? I think you mean that I should use map to get all the values ( that i have already tried out ) and then use for each on that to target the values one by one. correct ? Thanks !
  12. Hi Requinix ! Now that you point it out, I can see it 😥 ! Thanks ! And now that you told me, kindly help me resolve it as that as well ! I couldn't get the map function to resolve the issue so i used this instead : $.each(test_arr, function(i, item) { ... }); So please help me wrap all the fields in a single form so that they may be submitted with a single button click. Thanks loads !
  13. ajoo

    GHOST message !

    😃 Super ! I'll leave it at that then. Thanks a ton !
  14. ajoo

    GHOST message !

    Hi all ! I have an ajax page which is working great when it is in the root folder. It is triggered when a certain values dips below a predefined value while a valid user is logged in. The page is simply a form with a drop down and a text box and a message bar at the bottom. The message displays appropriate success or false messages. Everything works good. However I wanted to move the ajax.php into the includes folder outside of the webroot and I did so. The form still works great but the message bar returns my messages embedded somewhere inside entire index.html loaded so far. There are no errors or access errors. The message returned is equated to an empty string at the beginning inside the ajax.php and then populated with the appropriate message which is echoed back. I simply cannot make out where it is picking up the entire index.HTML from and more importantly why ? Please help. Thanks.
  15. ajoo

    GHOST message !

    Well I moved the ajax.php outside the root simply because I think that would be a safer place for the code or at least as much as can be moved there. I may be wrong. There are some mixed responses on this on the net. What would you suggest ? See I am unsure and so I am asking. Thanks.
  16. ajoo

    GHOST message !

    HI Requinix, I meant a pointer in the right direction. Since the get variable tactic is returning the wrong result and I have no clue, as of now, how to proceed maybe you can tell me what else I could try. Thanks !
  17. ajoo

    GHOST message !

    Hi requinix, Thanks for clarifying that. In my previous reply I have mentioned that I am able to access the ajax file in includes (outside the root) using a get variable. If I was just to go by the success or failure message returned by the ajax function, I would be good because the ajax call does what it's supposed to do and works great. However the issue is that the return value received by this method is the complete index.html while I just wanted a custom message to be returned signalling failure or success. I have no clue how I may be able to return just the message and not the whole index.html. I was hoping you would be able to show me how that could be done or not. ( my custom messages are also returned embedded in the index.html) Thanks.
  18. ajoo

    GHOST message !

    Hi Requinix, What's that supposed to mean please! ? 😃 Ok So I know somewhat the issue that is. It's happening because I had to change the action value of my form to pass through a GET value as variable to my index file where as earlier it was the ajax.php itself. To be more clear, earlier I had action = "ajax.php ", but now with the file in the includes folder outside the root, it's index.php?page=ajax. But with the file outside the root, i need this. Correct? So please enlighten me how may I fix this to get only the desired output returned? You think i am worrying too much about security ? Like it's ok to let the files be in the root and not move them outside it? Thanks !
  19. ajoo

    <th> properties via css

    Hi Requinix, I found and read https://css-tricks.com/specifics-on-css-specificity/ and was able to resolve my issue. I too thought that putting a class within the <td > or <th > element , would cause the defaults to be overridden. I still applied the class to each <th> and <td> element but that's ok. Thanks Requinix for putting up with my slow grasping !🙃
  20. ajoo

    <th> properties via css

    Hi all !. I have a table as shown below: S.No, COL A, COL B, COL C, COL D and Actions are the <th> fields in one row and and WSes, VSes, TSes and XSes are in the <th> in the next row. The table is exactly as I want but I have to use inline styling to set the text alignment property of the <th>es in the two rows. The first one being center aligned and the 2nd ones right aligned as seen. I wish to do the styling using css and remove the inline styling. Is there a was for me to target the <th>es of the two rows separately and change their text-align properties. Thanks all !
  21. ajoo

    <th> properties via css

    This I understand !! So if this destroys the inheritance, then shouldn't the text-align: center set by the class within td work as intended ? The thing is that this same table css values works great for many of my tables and don't wish to alter those. In this case since all values of data are numeric I want them right aligned ( there is another class = trow2 { text-align : right}) but there are two values SNo and the Action that I wanted center aligned. So instead of changing the <tr> which affects all other tables i decided to change the <td> values in this particular table. Can you please show me how would you rectify this !? Thanks loads !
  22. ajoo

    <th> properties via css

    Hi, Shouldn't the class trow1's text-align : center override the default td text-align :left ? Doesn't seem to be doing so. I do believe that the class has a higher specificity than the <td> element of the table? CSS .TFtable td{ padding:6px; border:#4e95f4 1px solid; text-align: left; } .trow1{ text-align: center; } HTML <tr> <td class='trow1'>{$din}</td> <td class='trow2'>{$wrt1}</td> <td class='trow2'>{$wrt2}</td> <td class='trow2'>{$wrt3}</td> . . . </tr> Please advise. Thanks !
  23. ajoo

    <th> properties via css

    Hi Requinix, I was not aware that I could use classes inside the <th>, <tr> etc. elements of the tables 🤔. Thanks for the clarification. I should be able to sort this then. Thanks loads !
  24. ajoo

    <th> properties via css

    Hi ! Since I am using CSP, it does not allow this to be used without the complication of adding a nonce for these. I was hoping to avoid that. Could you please explain cos I am not sure I understand what you mean by this. What classes ? You mean like classes in divs ? Is something like <th class = "someclass" permitted? Haven't seen that for tables. Thanks !
  25. ajoo

    <th> properties via css

    Yes that's correct ! But the thing is that this would still be an inline styling and I want to remove that altogether and move it into css because this gives me CSP errors !! So is there a way to move the styling into CSS and target the text align property of the <tr>s or <th>s from there. Thanks !
×

Important Information

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.