0

i want to get only the parse value of the html field here's my html.

 <tr valign="baseline">
   <td nowrap align="left"><label>data:</label></td>
     <td><input type="text" name="data" id="data" size="32" value=""></td>
   </tr>

and here's my jquery inside onclick function.

data =$("#try").html();

  $("#data").val(data);

            console.log("error");

and here's the result that display in the field

<p class="1">1</p><p class="2">2</p><p class="3">3</p>

i want to get only the value of P. its like 123 using php hope anyone can help me as soon as possible. thanks in advance.

3 Answers 3

1

Use .text() instead of html()

var data = $("#try p").text();

$("#data").val(data);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr valign="baseline">
    <td nowrap align="left">
      <label>data:</label>
    </td>
    <td>
      <input type="text" name="data" id="data" size="32" value="">
    </td>
  </tr>
</table>
<div id="try">
  <p class="1">1</p>
  <p class="2">2</p>
  <p class="3">3</p>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

it works. thankyou for your fast response Mr. Arun :)
0

your description is a little confusing. But if I got it right you end up with a string like

<p class="1">1</p><p class="2">2</p><p class="3">3</p>

And you have to filter that string in PHP, not in JS.

If so, just use strip_tags

echo strip_tags('<p class="1">1</p><p class="2">2</p><p class="3">3</p>');

Hope that is what you are looking for

Regards,

Stefan

3 Comments

i get this value <p class="1">1</p><p class="2">2</p><p class="3">3</p> when clicking the row in datatable and it's the id of the selected item. another question how can i get the whole value of selected row in getting only the id and send it to another table in database. hope my question is clear.
well, I am afraid, it isnt. First of all: I do not get why you have to parse anything in PHP. Actually I do not even get what you are trying to do here at all. And Secondly: Without a proper description of what you are trying to achieve, its going to be a challenge to help you
sorry for being confusing, my friend told me that the solution to my problem is to parse it first because when i getting the id it has a html tag. i really want is to get the value of selected row and send it to another table in database. and i think it's possible but i really need help because im trapped. hope anyone can help me.
0

As I understand you want to get the value of the text input without p tags you can do it using jquery by following jquery script

    data = $("#data").val();

alert($(data).text());
</pre>

or by PHP using $data = $_GET ['data']; echo strip_tags($data);

1 Comment

atleast give an explanation about your answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.